#define _CRT_SECURE_NO_WARNINGS 1
#include "vector.h"

void test_vector01()
{
	xsc::vector<int> iv;
	iv.push_back(1);
	iv.push_back(2);
	iv.push_back(3);
	iv.push_back(4);
	iv.push_back(5);
	iv.printvector();

	//迭代器失效，p已经改变了指向
	auto p = find(iv.begin(), iv.end(), 2);
	p = iv.insert(p, 40);
	(*p) *= 10;

	iv.printvector();

}


void test_vector02()
{
	xsc::vector<int> iv;
	iv.push_back(1);
	iv.push_back(2);
	iv.push_back(2);
	iv.push_back(2);
	iv.push_back(2);
	iv.push_back(2);
	iv.push_back(2);
	iv.push_back(3);
	iv.push_back(4);
	iv.push_back(4);
	iv.push_back(5);
	iv.printvector();

	//iv.erase(iv.begin());
	/*iv.printvector();*/

	auto itor = iv.begin();
	while (itor != iv.end())
	{
		if (*itor % 2 == 0)
		{
			itor = iv.erase(itor);
		}
		else
		{
			++itor;

		}

	}
	iv.printvector();

}


void test_vector03()
{
	/*xsc::vector<double> dv;
	dv.push_back(1.1);
	dv.push_back(1.2);
	dv.push_back(1.3);
	dv.push_back(1.4);

	dv.printvector();*/


	xsc::vector<int> iv;
	iv.push_back(1);
	iv.push_back(2);
	iv.push_back(3);
	iv.push_back(4);
	iv.push_back(5);
	iv.printvector();

	cout << endl;

	xsc::vector<int> iv2(iv);
	iv2.printvector();

	xsc::vector<int> iv3;

	iv3 = iv2;
	iv3.printvector();

	xsc::vector<int> iv4(10, 1);
	iv4.printvector();
}

void test_vector04()
{
	xsc::vector<string> sv;
	sv.push_back("1111111111111111111111111");
	sv.push_back("1111111111111111111111111");
	sv.push_back("1111111111111111111111111");
	sv.push_back("1111111111111111111111111");
	sv.push_back("1111111111111111111111111");

	sv.printvector();

	xsc::vector<string> sv1;
	sv1.push_back("hello world");
	sv1.printvector();

	sv1 = sv;
	sv1.printvector();
}

void test_memmove()
{
	/*char arr[] ="12345";
	char* p = new char[6];
	memmove(p, arr, 3 * sizeof(char))*/;
	

	/*string s1(10,'x');
	string s2();
	memmove(s2, s1, s1.size());
	*/
}


//int main()
//{
//	test_vector04();
//
//	//test_memmove();
//
//	/*xsc::vector<int> v;
//	v.push_back(1);
//	v.push_back(2);
//	v.push_back(3);
//	v.push_back(4);
//
//	v.printvector();
//	cout << v.size() << endl;
//
//	v.resize(1);
//	cout << v.size() << endl;
//
//	v.resize(10);
//	v.printvector();
//	cout << v.size() << endl;*/
//
//	return 0;
//}

int main()
{
	string s("hello world");

	//malloc不会自动调用构造函数，要显示调用
	string* s1 = (string*)malloc(sizeof(string));
	new(s1)string;
 
	s1->~basic_string();
	free(s1);
	s1 = nullptr;

	return 0;
}